/* -*- mode: c; c-basic-offset: 8; tab-width: 8; indent-tabs-mode: t -*- */
// #include<stdio.h>
// #include<stdlib.h>
#include "delay.h"
#include "printf.h"
#include "mmu.h"


__attribute__ ((section (".stack")))
__attribute__((unused))
static char stack[1024*1024];

void semihosting_putc(int c) {
	asm volatile (
		"mov	x1, %0\n\t"
		"mov	x0, #3\n\t"
		"hlt	0xf000\n\t"
		:
		: "r" (&c)
		: "x0", "x1", "memory"
	);
}

void semihosting_shutdown() {
	asm volatile (
		"mov	w0, 0x18\n"
		"mov	x1, #0x20000\n"
		"add	x1, x1, #0x26\n"
		"hlt	#0xF000\n"
		:
		:
		: "x0", "x1", "memory"
	);
}

extern long __bss_start, __bss_end, __bss_size;
extern long __stack_start, __stack_end, __stack_size;
long array_size[5];
void calc_section_size(void)
{
	int array1[8];
	char asdf[128];
	int array2[8];

	array_size[0] = 10;
	array_size[1] = 11;
	array_size[2] = 12;
	// memset(size, 0x55, sizeof(size));
	printf("Hello world!\n");
	printf("bss-start 0x%x\n", &__bss_start);
	printf("bss-end   0x%x\n", &__bss_end);
	printf("bss-size  0x%x\n", &__bss_end - &__bss_start);

	delay(3 * 1000);
	printf("stack-start 0x%x\n", &__stack_start);
	printf("stack-end   0x%x\n", &__stack_end);
	printf("stack-size  0x%x\n", &__stack_end - &__stack_start);

	printf("array1 0x%x\n", array1);
	printf("asdf   0x%x\n", asdf);
	printf("array2 0x%x\n", array2);


}


int main(void) {
	// mmu_init();
	calc_section_size();
	semihosting_shutdown();
	return 0;
}
